# -*- coding: utf-8 -*-
# @Author  : lang
import datetime
import os
import time


# 定义一个函数，用来装饰testcase, test开头的方法 ，方便截屏
from functools import wraps

# from common.bo import CHROME
# driver = CHROME().browser

def take_shots(function):

    @wraps(function)
    def get_err_img(self, *args, **kwargs):

        try:
            function(self, *args, **kwargs)
        except:

            now = datetime.datetime.fromtimestamp(time.time()).strftime("%Y%m%d_%H%M%S")

            fileName = now + "_" + function.__name__ + ".png"

            path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, "screenshots"))

            self.driver.get_screenshot_as_file(filename=os.path.join(path, fileName))

            raise

    return get_err_img


